import { HOST } from "@/api/constant";
export const viewImg = (img) => {
  if (!img) {
    return "";
  }
  let imgUrl = "";
  // 判断图片是否是网络图片
  if (img.startsWith("http") || img.startsWith("https")) {
    imgUrl = img;
  } else {
    imgUrl = HOST + img;
  }
  return imgUrl;
};

export const richImg = (content) => {
  const result = content?.replace(
    /<img[^>]+src=['"](['"])+['"]>/g,
    (match, src) => {
      console.log(src);
      return match.replace(src, viewImg(src));
    }
  );
  return result || content;
};
